/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.app.controller;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import com.yanlight.Constants;
import com.yanlight.util.KaptchaUtil;
import com.yanlight.util.SessionUtil;

/**
 * 
 *
 * @author haolw
 * time 2017/08/18
 */
@Controller
public class VerifyController {
	
	@GetMapping(value = "/verify/get")
	public void verifyCode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control", "no-store, no-cache");
		response.setContentType("image/jpeg");
		String code = KaptchaUtil.generateVerifyCode(5);
		SessionUtil.saveAttribute(Constants.VERIFY_CODE, code);
		ServletOutputStream out = response.getOutputStream();
		KaptchaUtil.outputImage(out, code);
		return;
	}
}
